<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- styling.qdoc -->
  <title>Use Case - Style And Theme Support | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Use Case - Style And Theme Support</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#using-the-styling-qml-types">Using the Styling QML Types</a></li>
<li class="level1"><a href="#accessing-the-system-palette">Accessing the System Palette</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Use Case - Style And Theme Support</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-usecase-styling.html-description -->
<div class="descr"> <a name="details"></a>
<p>Styling with QML involves creating a visual type and binding that to a property or by directly assigning a value to a property. For types that incorporate Qt Quick's <a href="../qtquick/qtquick-modelviewsdata-modelview.html">delegates</a> the visual type attaches to the <i>delegate</i> property.</p>
<p>When using <a href="../qtquickcontrols1/qtquickcontrols1-index.html">Qt Quick Controls 1</a>, the controls automatically set the appropriate style from the respective <a href="supported-platforms.html">platforms</a>.</p>
<a name="using-the-styling-qml-types"></a>
<h2 id="using-the-styling-qml-types">Using the Styling QML Types</h2>
<p>The <a href="../qtquickcontrols1/qtquickcontrols1-index.html">controls</a> have a <code>style</code> property to which the <i>styling types</i> bind. The controls have a corresponding styling type from the <a href="../qtquickcontrols1/qtquick-controls-styles-qmlmodule.html">Qt Quick Controls 1 Styles</a> module. For example, <a href="../qtquickcontrols1/qml-qtquick-controls-button.html">Button</a> has a <a href="../qtquickcontrols1/qml-qtquick-controls-styles-buttonstyle.html">ButtonStyle</a> type and <a href="../qtquickcontrols1/qml-qtquick-controls-menu.html">Menu</a> has a <a href="../qtquickcontrols1/qml-qtquick-controls-styles-menustyle.html">MenuStyle</a> type. The styling types provide properties applicable to their respective controls such as the background, label, or for some controls, the cursor appearance.</p>
<pre class="qml">

  <span class="type"><a href="../qtquickcontrols/qml-qtquick-controls2-button.html">Button</a></span> {
      <span class="name">text</span>: <span class="name">qsTr</span>(<span class="string">&quot;Hello World&quot;</span>)
      <span class="name">style</span>: <span class="name">ButtonStyle</span> {
          <span class="name">background</span>: <span class="name">Rectangle</span> {
              <span class="name">implicitWidth</span>: <span class="number">100</span>
              <span class="name">implicitHeight</span>: <span class="number">25</span>
              <span class="name">border</span>.width: <span class="name">control</span>.<span class="name">activeFocus</span> ? <span class="number">2</span> : <span class="number">1</span>
              <span class="name">border</span>.color: <span class="string">&quot;#FFF&quot;</span>
              <span class="name">radius</span>: <span class="number">4</span>
              <span class="name">gradient</span>: <span class="name">Gradient</span> {
                  <span class="type"><a href="../qtquick/qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0</span> ; <span class="name">color</span>: <span class="name">control</span>.<span class="name">pressed</span> ? <span class="string">&quot;#ccc&quot;</span> : <span class="string">&quot;#fff&quot;</span> }
                  <span class="type"><a href="../qtquick/qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">1</span> ; <span class="name">color</span>: <span class="name">control</span>.<span class="name">pressed</span> ? <span class="string">&quot;#000&quot;</span> : <span class="string">&quot;#fff&quot;</span> }
              }
          }
     }

</pre>
<p><b>Note: </b><a href="../qtquickcontrols1/qtquick-controls-styles-qmlmodule.html">Qt Quick Controls 1 Styles</a> was introduced in Qt 5.1 and requires <a href="../qtquick/qtquick-index.html">Qt Quick</a> 2.1&#x2e;</p><a name="accessing-the-system-palette"></a>
<h2 id="accessing-the-system-palette">Accessing the System Palette</h2>
<p>The <a href="../qtquick/qml-qtquick-systempalette.html">SystemPalette</a> type provides information about the system's palette information. QML applications can use this information to set the appearance of visual types to match the native look-and-feel. In addition, on <a href="supported-platforms.html#desktop-platforms">desktop</a> platforms, different color palettes are employed when changing states, for example, when the application loses keyboard focus.</p>
<p>When using the <a href="../qtquickcontrols1/qtquickcontrols1-index.html">controls</a>, the system colors are already used.</p>
</div>
<!-- @@@qtquick-usecase-styling.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
